<?php
	require ('../api/config.php');
	$fid = isset($_GET['fid']);
	$validWidPattern = '/^\d+$/';
	if (!preg_match($validWidPattern, $fid) and $fid!=NULL)  {
		echo '<script><script> alert("非法请求，GET数据错误！"); window.location.href="../";</script>';  
		exit();
	} 
	if($username==NULL){echo '<script>alert("请先登陆账号！"); 
	window.location.href="../login.php?fid='.$fid.'"</script>';exit();
	}

?>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="/style/vue/vue.global.js"></script>
    <script src="/style/vue/axios.min.js"></script>
    <script src="/style/vue/md5.min.js"></script>
    <link rel="stylesheet" href="/style/css/index.css">
    <link rel="stylesheet" href="/style/css/tc.css">
    <link rel="stylesheet" href="/style/css/admin.css">
    <title>新建收集表 | TOP图片收集管理系统</title>
</head>
<body>
    <div id="app">
        <div id="top">
            <div id="title">
                <h1 id="titles">{{ titlestat }}</h1>
            </div>
            <div id="list">
                <div id="list_tb">
                    <img src="../style/image/gd.png" alt="下拉列表">
                </div>
                <div class="list">
                    <ul>
                        <li id="list_li"><a :href="adminht">收集表后台</a></li>
                        <li id="list_li"><a :href="adminall">查看收集总图</a></li>
                        <li id="list_li"><a href="./list.html" target="_blank">历史收集列表</a></li>
                    </ul>
                </div>
            </div>
        </div>
    
        <div id="msg">
    
            <div id="sum2" class="xingming">
                <div id="sum3">
                    <span id="xmts"><img src="../style/image/mc.png" alt="名称"> <b>*</b> 图片收集表标题（压缩包同名）</span>
                </div>
                <span id="inputname"><input type="text" id="titlesz" required placeholder="收集表标题（20字以内）" maxlength="20" v-model="titlesz"></span>
            </div>
    
            <div id="sum2" class="xingming">
                <div id="sum3">
                    <span id="xmts"><img src="../style/image/ts.png" alt="提示"> 提交须知</span>
                </div>
                <span id="inputname">
                    <textarea  type="text" id="msgsz" wrap="virtual"  rows="" cols="" required placeholder="（200字以内）" maxlength="200" v-model="msgsz"></textarea>
                </span>
            </div>
    
            <div id="sum2" class="xingming">
                <div id="sum3">
                    <span id="xmts"><img src="../style/image/dx.png" alt="对象"> <b>*</b> 收集的对象</span>
                </div>
                <span id="inputname">
                    <select name="class" v-model="classsz" id="classsz">
                        <option value="">— 请选择 —</option>
                        <option value="通用">通用</option>
                        <option value="名单示例">名单示例</option>
                    </select>
                </span>
            </div>
    
            <div id="sum2" class="xingming">
                <div id="sum3">
                    <span id="xmts"><img src="../style/image/rq.png" alt="rq"> <b>*</b> 收集表截止时间</span>
                </div>
                <span id="inputname">
                    <input type="datetime-local" name="stoptime" v-model="stoptimesz" id="stoptimesz">
                </span>
            </div>
    
            <div class="tijiao" v-if="tijiao">
                <span id="tj"><input type="submit" id="go" v-model="go"  @click="gos()"></span>
            </div>
        </div>
    
        <div id="bottom" style="position: fixed;bottom: 0px;left: 0px;">
            Opyright © 2024 TOP图片收集管理系统 All Rights Reservedby.
        </div>
    
        <div id="tc0" class="tc" v-if="tanchuang">
            <span>正在{{ go }}收集表，请稍等……</span>
            <div class="tcjdt">
                <div class="tcrect"></div>
            </div>
        </div>
    </div>
    
</body>
    <script>
        const App = {
            data() {
                return {
                    titlesz:'',stoptimesz:'',msgsz:'请按时提交截图',tijiao:true,tanchuang:false,
                    fid:'',classsz:'',titlestat:'新建收集表',go:'确认新建',fun:'xinjian',
                    tijiao:true,tanchuang:false,
                    username:'',password:'',qqnum:'',uname:'',
                    adminall:'./list.html',adminht:'./list.html'
                }
            }, methods: {
                get_fid:function(){
                    //获取GET后面的参数
                    var url = decodeURIComponent(location.search); 
                    var cs = new Object();
                        if (url.indexOf("?") != -1) {
                        var str = url.substr(1);
                        strs = str.split("&");
                        for(var i = 0; i < strs.length; i++) {
                            cs[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                        }
                        var fid = cs.fid;
                        this.fid = cs.fid;
                    }
                    return fid;
                },
                axio:function(id){
                    //请求服务器，收集表的信息
                    var that = this;
                    axios.post("../../api/upadmin.php",{fun:"bianjiqingqiu",fid:id,uname:this.uname})
                        .then(function(resp) {
                            var data = resp.data;
							if(data.stat == 200){
							 //   alert(data);
								document.title = '编辑·'+data.title;
								that.titlestat = '编辑·'+data.title;
								that.go = '确认修改';
								that.titlesz = data.title;
								that.stoptimesz = data.stoptime;
								that.msgsz = data.msg;
								that.classsz = data.class;
								$("#stoptimesz").val(data.stoptime);
							}else if(data.stat == '400'){
                                alert(data.msg);
                                //window.location.href='./new.php';
                            }else{
								alert('错误！访问的收集表不存在！');
							}
                        }).catch(function(err){
                            console.log(err);
                        });
                    
                },
                gos:function(){
                    if(this.titlesz=='' || this.classsz=='' || this.stoptimesz==''){
                        alert("* 是必填项，请填写完整！");
                    }else{
                        // this.tijiao=false;
                        // this.tanchuang=true;
                        var that = this;
						if(this.go == '确认修改'){
							this.fun = 'bianji';
						}else if(this.go == '确认新建'){
							this.fun = 'xinjian';
						}else{
							alert('错误！非法的参数！');
						}
                        axios
                            .post("../api/upadmin.php",{
                                fun:this.fun,
								fid:this.fid,
                                title:this.titlesz,
                                msg:this.msgsz,
                                class:this.classsz,
                                stoptime:this.stoptimesz,
                                uname:this.uname
                            })
                            .then(function(resp) {
                                var data = resp.data;
                                if(data.stat == '200'){
									if(that.fun == 'xinjian'){
										alert('新建成功！请点击确认！');
										var fid = data.fid;
										window.location.href='../index.php?fid='+fid;
									}else if(that.fun == 'bianji'){
										alert('修改成功！请点击确认！');
										that.axio(data.fid);
										window.location.href='../index.php?fid='+that.fid;
									}
								}else if(data.stat == '400'){
									if(data.msg =="你没有权限，请你先登录！"){
                                    alert('你没有权限，请你先登录！');
                                    window.location.href='../../login.php?t=全部图片&w=upfile/admin/all.html?fid='+that.fid;
                                    }else{
                                        alert(data.msg);
                                    }
								}else{
									alert('写入数据时，服务器发生未知错误\n\n错误参数:'+data);
								}
								// that.tijiao=true;
								// that.tanchuang=false;
                            });
                    }
                },
                md5:function(mima){
                    if(mima==null || mima==''){var mima = new Date().getTime();}
                    var md5mima = '00000000000000000000000000011000011010100000';
                    var md5key = '00000000000000000000101111000110000101001110';
                    var md5mima=parseInt(md5mima,2);
                    var md5key=parseInt(md5key,2);
                    var ver = md5(parseInt(mima/md5mima)+md5key);
                }
                
            },mounted:function(){
                this.fid = this.get_fid();
                if(this.fid != '' && this.fid != null && this.fid!='undefined'){
                    this.axio(this.fid);
                    this.adminall = './all.html?fid='+this.fid;
					this.adminht = './admin.php?fid='+this.fid;
                }
            },created(){
            }
        }
    
        Vue.createApp(App).mount('#app')
    
        
    </script>
</html>